<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 28] The java.net Package</TITLE>
<META NAME="author" CONTENT="David Flanagan">
<META NAME="date" CONTENT="Thu Jul 31 16:30:53 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java in a Nutshell">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">
<script language='JavaScript'>
<!--
if (location.replace) {
 location.replace ('ch28_js.htm');
}
// -->
</script>

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java in a Nutshell" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch27_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 28</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch28_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<H1 CLASS=chapter><A CLASS="TITLE" NAME="JNUT2-CH-28">28. The java.net Package</A></H1>

<DIV CLASS=htmltoc>

<p>
<b>Contents:</b><br>
<a href='ch28_02.htm'>java.net.ConnectException (JDK 1.1)</a><br>
<a href='ch28_03.htm'>java.net.ContentHandler (JDK 1.0)</a><br>
<a href='ch28_04.htm'>java.net.ContentHandlerFactory (JDK 1.0)</a><br>
<a href='ch28_05.htm'>java.net.DatagramPacket (JDK 1.0)</a><br>
<a href='ch28_06.htm'>java.net.DatagramSocket (JDK 1.0)</a><br>
<a href='ch28_07.htm'>java.net.DatagramSocketImpl (JDK 1.1)</a><br>
<a href='ch28_08.htm'>java.net.FileNameMap (JDK 1.1)</a><br>
<a href='ch28_09.htm'>java.net.HttpURLConnection (JDK 1.1)</a><br>
<a href='ch28_10.htm'>java.net.InetAddress (JDK 1.0)</a><br>
<a href='ch28_11.htm'>java.net.MalformedURLException (JDK 1.0)</a><br>
<a href='ch28_12.htm'>java.net.MulticastSocket (JDK 1.1)</a><br>
<a href='ch28_13.htm'>java.net.NoRouteToHostException (JDK 1.1)</a><br>
<a href='ch28_14.htm'>java.net.ProtocolException (JDK 1.0)</a><br>
<a href='ch28_15.htm'>java.net.ServerSocket (JDK 1.0)</a><br>
<a href='ch28_16.htm'>java.net.Socket (JDK 1.0)</a><br>
<a href='ch28_17.htm'>java.net.SocketException (JDK 1.0)</a><br>
<a href='ch28_18.htm'>java.net.SocketImpl (JDK 1.0)</a><br>
<a href='ch28_19.htm'>java.net.SocketImplFactory (JDK 1.0)</a><br>
<a href='ch28_20.htm'>java.net.UnknownHostException (JDK 1.0)</a><br>
<a href='ch28_21.htm'>java.net.UnknownServiceException (JDK 1.0)</a><br>
<a href='ch28_22.htm'>java.net.URL (JDK 1.0)</a><br>
<a href='ch28_23.htm'>java.net.URLConnection (JDK 1.0)</a><br>
<a href='ch28_24.htm'>java.net.URLEncoder (JDK 1.0)</a><br>
<a href='ch28_25.htm'>java.net.URLStreamHandler (JDK 1.0)</a><br>
<a href='ch28_26.htm'>java.net.URLStreamHandlerFactory (JDK 1.0)</a><br>
<p>
<p>
</DIV>

<P CLASS=para>
The <tt CLASS=literal>java.net</tt> package provides a powerful and
flexible infrastructure for networking.
<A HREF="ch28_01.htm#JNUT2-CH-28-FIG-1">Figure 28.1</A>
shows the class hierarchy for this package. Many of the
classes in this package are part of the networking
infrastructure and are not used by normal applications;
these complicated classes can make the package a difficult
one to understand. In this overview we describe only the
classes that an application might normally use.<A NAME="CH28.JAVA.NET.PAC1"></A>

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JNUT2-CH-28-FIG-1">Figure 28.1: The java.net package</A></h4>


<p>
<img align=middle src="./figs/jn2_2801.gif" alt="[Graphic: Figure 28-1]" width=464 height=553 border=0>

</DIV>

<P CLASS=para>
The <tt CLASS=literal>URL</tt> class represents an Internet Uniform
Resource Locator. It provides a very simple interface to
networking--the object referred to by the URL can be
downloaded with a single call, or streams may be opened to
read from or write to the object.

<P CLASS=para>
At a slightly more complex level, the <tt CLASS=literal>URLConnection</tt>
object may be obtained from a given <tt CLASS=literal>URL</tt> object. The
<tt CLASS=literal>URLConnection</tt> class provides additional methods that
allow you to work with URLs in more sophisticated ways.

<P CLASS=para>
If you want to do more than simply download an object
referenced by a URL, you can do your own networking with the
<tt CLASS=literal>Socket</tt> class. This class allows you to connect to a
specified port on a specified Internet host and read and
write data using the <tt CLASS=literal>InputStream</tt> and
<tt CLASS=literal>OutputStream</tt> classes of the <tt CLASS=literal>java.io</tt>
package. If you want to implement a server to accept
connections from clients, you can use the related
<tt CLASS=literal>ServerSocket</tt> class. Both <tt CLASS=literal>Socket</tt> and
<tt CLASS=literal>ServerSocket</tt> use the <tt CLASS=literal>InetAddress</tt> address
class, which represents an Internet address.

<P CLASS=para>
The <tt CLASS=literal>java.net</tt> package allows you to do low-level
networking with <tt CLASS=literal>DatagramPacket</tt> objects which may be
sent and received over the network through a
<tt CLASS=literal>DatagramSocket</tt> object.  In Java 1.1, the package has been
extended to include a <tt CLASS=literal>MulticastSocket</tt> class that
supports multicast networking.

<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JNUT2-CH-28-SECT-1">28.1 java.net.BindException (JDK 1.1)</A></h2>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-28-SECT-1.1"></A></h3>
</DIV>

<P CLASS=para>
This exception signals that a socket could not be bound to a
local address and port.  This often means that the port is
already in use.

<DIV CLASS=screen>
<P>
<PRE>
public class <tt CLASS=literal>BindException</tt> extends SocketException {
    // <tt CLASS=literal>Public Constructors</tt>
            public <tt CLASS=literal>BindException</tt>(String <tt CLASS=literal>msg</tt>);
            public <tt CLASS=literal>BindException</tt>();
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-28-SECT-1.2">Hierarchy:</A></h3>

<P CLASS=para>
Object->Throwable(Serializable)->Exception->IOException->SocketException->BindException

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch27_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch28_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>java.math.BigInteger (JDK 1.1)</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>java.net.ConnectException (JDK 1.1)</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
